package com.g360.sys.web.controller;

import com.g360.sys.domain.Resource;
import com.g360.sys.domain.User;
import com.g360.sys.service.ResourceService;
import com.g360.sys.service.UserService;
import com.g360.sys.web.bind.annotation.CurrentUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Set;

/**
 * Created by vpc on 2016/3/29.
 */
@Controller
public class IndexController {
    @Autowired
    private ResourceService resourceService;
    @Autowired
    private UserService userService;

    @RequestMapping("/")
    public String index(@CurrentUser User loginUser, Model model) {
        // 默认取第一级菜单
        long parentId = 0l;

        Set<String> permissions = userService.findPermissions(loginUser.getUsername());

        List<Resource> menus = resourceService.findMenus(permissions,parentId);

        model.addAttribute("menus", menus);

        return "index";
    }

    @RequestMapping("/welcome")
    public String welcome() {
        return "welcome";
    }
}
